package bdqn;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class MainTest {
	public static void main(String[] args) throws ParseException {
		Scanner input = new Scanner(System.in);
		ImplClass imp = new ImplClass();
		System.out.println("**********欢迎进入青鸟新生入学登记系统************");
		System.out.println("我们开设了如下课程的年级：");
		imp.showGrade();
		System.out.println("1.继续\n0.退出\n请选择：");
		int choice = input.nextInt();
		switch (choice) {
		case 1:
			System.out.println("请输入年级编号");
			int gradeid = input.nextInt();
			boolean flag = imp.showSubject(gradeid);
			if (flag == false) {
				System.out.println("输入的年级编号不存在");
			}
			System.out.println("是否入学：1.是 2.否");
			int choice2 = input.nextInt();
			switch (choice2) {
			case 1:
				while (true) {
					System.out.println("请输入个人信息：");
					System.out.print("姓名：");
					String sname = input.next();
					System.out.print("性别：");
					String sex = input.next();
					System.out.print("来自哪个城市：");
					String fromcity = input.next();
					System.out.print("qq:");
					String qq = input.next();
					System.out.print("密码：");
					String password = input.next();
					Student s = new Student();
					s.setSname(sname);
					s.setSex(sex);
					s.setFromcity(fromcity);
					s.setQq(qq);
					s.setPassword(password);
					s.setGradeid(gradeid);
					long result = imp.register(s);
					if (result > 0) {
						System.out.println("恭喜你，入学登记成功，请牢记学号" + "【" + result
								+ "】");
						System.out.println("请登录：");
						while (true) {
							System.out.println("请输入学号：");
							long stuno = input.nextInt();
							System.out.println("请输入密码：");
							password = input.next();
							if (imp.login(stuno, password)) {
								System.out.println("登录成功");
								while (true) {
									System.out.println("请录入一门成绩：");
									System.out.print("科目号：");
									long sb_id = input.nextInt();
									System.out.println("得分：");
									long score = input.nextInt();
									System.out.println("考试日期：");
									Date exam_date = new SimpleDateFormat(
											"yyyy-MM-dd").parse(input.next());
									ExamResult e = new ExamResult(result,
											score, sb_id, exam_date);
									boolean bool = imp.addScore(e);
									if (bool) {
										System.out.println("成绩保存成功！");
										break;
									} else {
										System.out.println("录入成绩错误，请重新录入！");
									}
								}
								break;
							} else {
								System.out.println("登录错误，请重新登录！");
							}
						}
						break;
					} else {
						System.out.println("学生信息添加失败，请重新录入");
					}
				}
				break;
			case 2:
				System.out.println("取消入学！");
				break;
			}
			break;
		case 0:
			System.out.println("退出！")
			return;
		}

	}
}
